using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameLib.GameItem
{
    class GameButtonR : GameItem
    {
        protected Point frameSize;
        protected Rectangle frameBound;
        protected int currentFrame = 0;

        public GameButtonR(Texture2D texture, Vector2 pos, Point frameSize, int currentFrame, ItemManager man)
            : base(texture, man, pos)
        {
            this.frameSize = frameSize;
            this.currentFrame = currentFrame;
            frameBound = new Rectangle(currentFrame * frameSize.X, 0, frameSize.X, frameSize.Y);
        }

        public void NextFrame()
        {
            if ((currentFrame + 1) * frameSize.X < Texture.Width)
            {
                currentFrame++;
            }
            else
            {
                currentFrame = 0;
            }
            frameBound.X = currentFrame * frameSize.X;
        }

        public override bool CheckPress(Vector2 touchPos)
        {
            if (Enable)
            {
                if (touchPos.X < Position.X || touchPos.Y < Position.Y
                  || touchPos.X > (Position.X + frameSize.X) || touchPos.Y > (Position.Y + frameSize.Y))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return false;
            }
        }

        public override void Clean()
        {
            base.Clean();
        }

        public override void Update(GameTime gametime)
        {
            base.Update(gametime);
        }

        public override void Draw(SpriteBatch sp)
        {
            sp.Draw(Texture,
                    Position,
                    frameBound,
                    Color.White,
                    0,
                    Vector2.Zero,
                    1f,
                    SpriteEffects.None,
                    0);
        }
    }
}
